import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../components/Home.vue'
import Search from '../components/search.vue'
import Admin from '../components/admin/Admin.vue'
import Info from '../components/info/Info.vue'
import Comment from '../components/Comment.vue'

Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    component: Home
  },
  { path: '/search', component: Search },
  {
    path: '/admin',
    component: Admin
  },
  {
    path: '/info/:id/:dis',
    component: Info
  },
  {
    path: '/comment/:id',
    component: Comment
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  const tokend = window.sessionStorage.getItem('token')
console.log(to.path);
console.log(to.path.includes('comment'));

  if (to.path.includes('comment')) {
    if (!tokend) return next('/admin')
    next()
  }
  next()
})
export default router
